package com.ziyun.pop.web.modules.purchase.controller;

import com.utility.JsonUtils;
import com.utility.http.HttpUtils;
import com.ziyun.pop.common.utils.UserUtils;
import com.ziyun.pop.modules.purchase.entity.StoreMaterialSupplierEntity;
import io.renren.common.utils.R;
import io.renren.common.utils.StringUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


/**
 * 采购供应商
 *
 * @author guizhao
 * @date 2018-09-25 16:16:18
 */
@RestController
@RequestMapping("purchase/storematerialsupplier")
public class StoreMaterialSupplierController {

    @Value("${erpApi}")
    private String erpApi ;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){

        String url = erpApi + "/purchase/storematerialsupplier/list";

        String response =  HttpUtils.doPost(url,params);

        if(StringUtil.isEmpty(response)){
            return R.error("未获取到列表信息");
        }
        R rs = JsonUtils.string2Object(response, R.class);

        return rs;
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("purchase:storematerialsupplier:save")
    public R save(@RequestBody StoreMaterialSupplierEntity storeMaterialSupplier){
        storeMaterialSupplier.setCreateName(""+UserUtils.getCurentUser().getUsername());
        storeMaterialSupplier.setMsName(storeMaterialSupplier.getMsName().trim());

        Map<String,Object> params = new HashMap<>();
        params.put("storeMaterialSupplier",storeMaterialSupplier);

        String url = erpApi + "/purchase/storematerialsupplier/save";
        String response =  HttpUtils.doPost(url,params);

        return R.ok();
    }
}
